<?php

namespace app\apiadmin\service\behavior;

use app\apiadmin\model\behavior\InvitationMongo;

class InvitationService extends InvitationMongo
{

    /**
     * 邀请记录
     *
     * */
    public static function invitationList($param)
    {
        $param['query'] = array_merge($param['query'] ?? [], ['del'=>0, 'status'=>1]);
        $total = parent::total($param['query'] ?? []);
        $list = parent::list($param['query'] ?? [], $param['options'] ?? []);
        return [
            'total' => $total,
            'list' => $list,
        ];
    }

    /**
     * 签到记录
     *
     * */
    public static function singList($param)
    {
        $param['query'] = array_merge($param['query'] ?? [], ['del'=>0, 'status'=>2]);
        $total = parent::total($param['query'] ?? []);
        $list = parent::list($param['query'] ?? [], $param['options'] ?? []);
        return [
            'total' => $total,
            'list' => $list,
        ];
    }

    /**
     * 删除记录
     *
     * */
    public static function delId(string $id = null): bool
    {
        if (empty($id)) {
            return false;
        }
        return parent::del($id);
    }

    /**
     * 更新或插入记录
     *
     * */
    public static function addOrEdit($param)
    {
        if (empty($param)) {
            return false;
        }
        $data['query'] = [
            'live_id' => $param['live_id'],  // 直播ID
            'tutor_id' => $param['tutor_id'],  // 助教ID
            'user_id' => $param['user_id'],  // 用户ID
            'open_id' => $param['open_id'],  // 用户ID
            'del' => 0,
        ];
        $data['set'] = [
            '$set' => [
                'tutor_nickname' => $param['tutor_nickname'],  // 助教昵称
                'nickname' => $param['nickname'],  // 用户昵称
                'headimgurl' => $param['headimgurl'],  // 用户头像
                'phone' => $param['phone'],  // 用户手机号
                'status' => $param['status'],  // 1:预约 2:签到
                'booking_time' => time(),  // 预约时间
            ]
        ];
        $data['options'] = ['upsert' => true];
        return parent::addOrEdit($data);
    }
    
    
}
